package thread.demo01;

import lombok.AllArgsConstructor;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
 * 多线程下载图片
 */
@AllArgsConstructor
public class TestThread02  extends Thread{
    private  String url;
    private  String name;
        //https://www.bilibili.com/video/BV1V4411p7EF?p=5&spm_id_from=pageDriver

    @Override
    public void run() {
        WebDownloader.downLoader(url,name);
        System.out.println("下载了文件名为：："+ name);
    }


    public static void main(String[] args) {

        TestThread02 t1 = new TestThread02("https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/0b46f21fbe096b636678ddd40c338744eaf8acd5.jpg","t1.jpg");
        TestThread02 t2 = new TestThread02("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2390255124,2789605295&fm=26&gp=0.jpg","t2.jpg");
        TestThread02 t3 = new TestThread02("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2248364240,810524291&fm=26&gp=0.jpg","t3.jpg");
       t1.start();
       t2.start();
       t3.start();
    }

}



/*下载器*/
class  WebDownloader{

    public static void downLoader(String url,String Name){
        try {
            FileUtils.copyURLToFile(new URL(url),new File(Name));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
